package com.api.shopapi.mapper;

import com.api.shopapi.entity.Article;
import com.api.shopapi.entity.Train;
import com.api.shopapi.entity.dto.ArticleDTO;
import com.api.shopapi.entity.dto.TrainDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface TrainMapper {

    @Insert("insert into  train " +
            "(" +
            "trainCode, " +
            "trainClassCode, " +
            "trainClassName, " +
            "Title, " +
            "Description, " +
            "Content, " +
            "CreateTime, " +
            "Status, " +
            "GovernmentCode, " +
            "FileUrl1, " +
            "FileUrl2, " +
            "FileUrl3, " +
            "VideoUrl, " +
            "AskAnswerNameCode " +
            ") VALUES " +
            "(" +
            "#{train.trainCode} ," +
            "#{train.trainClassCode} ," +
            "#{train.trainClassName} ," +
            "#{train.Title} ," +
            "#{train.Description} ," +
            "#{train.Content} ," +
            "#{train.CreateTime} ," +
            "#{train.Status} ," +
            "#{train.GovernmentCode} ," +
            "#{train.FileUrl1} ," +
            "#{train.FileUrl2} ," +
            "#{train.FileUrl3}, " +
            "#{train.VideoUrl}, " +
            "#{train.AskAnswerNameCode} " +
            ") ")
    int insert(@Param("train") Train train);


    @Update("update train set " +
            "trainClassCode=#{train.trainClassCode}," +
            "trainClassName=#{train.trainClassName}," +
            "Title=#{train.Title}," +
            "Description=#{train.Description} ," +
            "Content=#{train.Content}," +
            "Status=#{train.Status}," +
            "FileUrl1=#{train.FileUrl1} ," +
            "FileUrl2=#{train.FileUrl2} ," +
            "FileUrl3=#{train.FileUrl3} ," +
            "VideoUrl=#{train.VideoUrl} ," +
            "AskAnswerNameCode=#{train.AskAnswerNameCode} " +
            " where " +
            " trainCode=#{train.trainCode}")
    int update(@Param("train") Train train);


    @Select("select * from train where trainCode=#{trainCode} ")
    Train getByTrainCode(@Param("trainCode") String trainCode);

    @Select("<script>" +
            "select  * from train" +
            " where GovernmentCode=#{governmentCode} " +
            "<if test ='title !=null and title!=\"\" '>" +
            " and Title like concat('%',#{title},'%') " +
            "</if>" +
            "<if test ='status != 0 '>" +
            " and Status = #{status} " +
            "</if>" +
            "<if test ='startTime !=null and startTime!=\"\" and endTime !=null and endTime!=\"\" '>" +
            " and StartTime between #{startTime} and #{endTime}" +
            "</if>" +
            " order by CreateTime desc " +
            "</script>")
    List<Train> getPageList(@Param("governmentCode") String governmentCode,
                               @Param("title") String title,
                               @Param("status")int status,
                               @Param("startTime")String startTime,
                               @Param("endTime")String endTime);


    @Select("<script>" +
            "select * from train" +
            " where GovernmentCode=#{governmentCode} " +
            " order by CreateTime desc " +
            "</script>")
    List<Train> listByGovCode(@Param("governmentCode") String governmentCode);


}
